package com.stylefeng.guns.modular.domain_manage.dao;

import com.stylefeng.guns.modular.domain_manage.model.DomainInfo;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 域名信息表 Mapper 接口
 * </p>
 *
 * @author GodRui
 * @since 2020-06-29
 */
public interface DomainInfoMapper extends BaseMapper<DomainInfo> {
    @Select("select id,domain_name as urlName,status,type,create_time as createTime from domain_info order by field(status ,'1', '2', '0');")
    List<DomainInfo> getAllDomainSortByStatus();

    @Select("select id,domain_name as urlName,status,create_time from domain_info where status = 1 and type = 0;")
    List<DomainInfo> getInuseDomains();

    @Select("select id,domain_name as urlName,status,create_time from domain_info where status = 1 and type = 1;")
    List<DomainInfo> getInuseResourceDomain();

    @Select("select id,domain_name as urlName,status,create_time from domain_info where status = 2 and type = 1;")
    List<DomainInfo> getBakResourceDomain();

    @Select("select * from domain_info where status = 2 and type = 0 limit #{size};")
    List<DomainInfo> getReadyDomains(Integer size);

    @Select("update domain_info set status = 1 where status = 2 and type = 0 limit #{size};")
    void changeRequireSizeToInuseDomain(Integer size);

    @Select("select count(*) from domain_info where status = 1 and type = 0;")
    Integer getInUseDomainSize();

    @Select("select count(*) from domain_info where status = 2 and type = 0;")
    Integer getReadyDomainSize();

    @Select("select app_code from application;")
    List<String> getAllAvailableAppCodes();
}
